home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Code / Chapter Code.exe / Chapter09 / StartPausePanel.java < prev    next >
Text File  |  2000-08-27  |  2KB  |  74 lines

  1.  
  2.  
  3.  
  4. package applets;
  5.  
  6. import shout3d.*;
  7. import shout3d.core.*;
  8. import shout3d.math.*;
  9.  
  10.  
  11. public class StartPausePanel extends Shout3DPanel implements DeviceObserver {
  12.    
  13.    
  14.    TimeSensor timer;
  15.    boolean started = false;
  16.  
  17.    public StartPausePanel (Shout3DApplet applet){
  18.       super(applet);
  19.    }
  20.    
  21.    
  22.    public void customInitialize() {
  23.       addDeviceObserver(this,"MouseInput", null);
  24.       timer =(TimeSensor) getNodeByName("world-TIMER");
  25.  
  26.  
  27.    }
  28.  
  29.    protected void finalize()  { 
  30.       removeDeviceObserver(this,"MouseInput");
  31.  
  32.    }
  33.  
  34.  
  35.    public boolean onDeviceInput(DeviceInput di, Object userData) {
  36.       MouseInput mi = (MouseInput) di;
  37.  
  38.       switch (mi.which){
  39.  
  40.          case MouseInput.DOWN:
  41.          
  42.             //if animation is not started
  43.             if (!started) {
  44.  
  45.                timer.start();
  46.                started = true;   
  47.                return true;
  48.             }
  49.             
  50.  
  51.              //if already started
  52.              else   {
  53.                
  54.                //if it's paused, unpause it
  55.                //or vice versa   
  56.                if (timer.isPaused())  {
  57.                   timer.setPaused(false);
  58.                   return true;
  59.                }
  60.                else {
  61.                   timer.setPaused(true);
  62.                   return true;
  63.                }                                 
  64.               }
  65.          
  66.       }//end of switch
  67.  
  68.       return false;
  69.       
  70.    }
  71.  
  72.    
  73.  
  74. } //end of class